package com.sojson.controller.po;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.sojson.entity.po.Salary;
import com.sojson.result.Result;
import com.sojson.service.SalaryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 工资控制器
 * 
 * @author liu
 * @date 2021-05-23
 */
@Api(tags = "工资管理")
@RestController
@RequestMapping("/salary")
public class SalaryController {

    @Autowired
    private SalaryService salaryService;

    /**
     * 单条插入
     * 
     * @param salary
     * @return
     */
    @PostMapping("/insert")
    @PreAuthorize("@ss.hasPermi('/salary/insert')")
    @ApiOperation("给工资添加一条数据")
    public Result<Integer> insert(@RequestBody Salary salary) {
        return Result.success(salaryService.insert(salary));
    }

    /**
     * 批量插入
     * 
     * @param salary
     * @return
     */
    @PostMapping("/insertList")
    @PreAuthorize("@ss.hasPermi('/salary/insertList')")
    @ApiOperation("给工资添加多条数据")
    public Result<Integer> insertList(@RequestBody Salary salary) {
        return Result.success(salaryService.insertList(salary));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param salary
     * @return
     */
    @DeleteMapping("/deleteByDto")
    @PreAuthorize("@ss.hasPermi('/salary/deleteByDto')")
    @ApiOperation("通过对象批量删除工资数据(物理删除)")
    public Result<Integer> deleteByDto(@RequestBody Salary salary) {
        return Result.success(salaryService.deleteByDto(salary));
    }

    /**
     * 统计全部数量
     * 
     * @return
     */
    @GetMapping("/countAll")
    @PreAuthorize("@ss.hasPermi('/salary/countAll')")
    @ApiOperation("统计工资全部数据(包含逻辑删除的)")
    public Result<Integer> countAll() {
        return Result.success(salaryService.countAll());
    }

    /**
     * 查询所有
     * 
     * @return
     */
    @GetMapping("/listAll")
    @PreAuthorize("@ss.hasPermi('/salary/listAll')")
    @ApiOperation("查询工资所有数据(包含逻辑删除的)")
    public Result<List<Salary>> listAll() {
        return Result.success(salaryService.listAll());
    }

    /**
     * 根据对象统计数量
     * 
     * @param salary
     * @return
     */
    @GetMapping("/countByDto")
    @PreAuthorize("@ss.hasPermi('/salary/countByDto')")
    @ApiOperation("根据对象统计工资数据")
    public Result<Integer> countByDto(Salary salary) {
        return Result.success(salaryService.countByDto(salary));
    }

    /**
     * 根据对象查询
     * 
     * @param salary
     * @return
     */
    @GetMapping("/listByDto")
    @PreAuthorize("@ss.hasPermi('/salary/listByDto')")
    @ApiOperation("根据对象查询工资数据")
    public Result<List<Salary>> listByDto(Salary salary) {
        return Result.success(salaryService.listByDto(salary));
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    @PreAuthorize("@ss.hasPermi('/salary/deleteById/{id}')")
    @ApiOperation("通过id删除工资数据(物理删除)")
    @ApiImplicitParam(name = "id", value = "id")
    public Result<Integer> deleteById(@PathVariable Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(salaryService.deleteById(id));
    }

    /**
     * 通过id数组删除(物理删除)
     * 
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds/{ids}")
    @PreAuthorize("@ss.hasPermi('/salary/deleteByIds')")
    @ApiOperation("通过id数组删除工资数据(物理删除)")
    @ApiImplicitParam(name = "ids", value = "id数组")
    public Result<Integer> deleteByIds(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(salaryService.deleteByIds(ids));
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateAllById")
    @PreAuthorize("@ss.hasPermi('/salary/updateAllById')")
    @ApiOperation("通过id更新工资数据(全部更新)")
    public Result<Integer> updateAllById(@RequestBody Salary salary) {
        return Result.success(salaryService.updateAllById(salary));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateAllByIdList")
    @PreAuthorize("@ss.hasPermi('/salary/updateAllByIdList')")
    @ApiOperation("通过id列表更新工资数据(全部更新)(更新内容相同)")
    public Result<Integer> updateAllByIdList(@RequestBody Salary salary) {
        return Result.success(salaryService.updateAllByIdList(salary));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateDtoListAllById")
    @PreAuthorize("@ss.hasPermi('/salary/updateDtoListAllById')")
    @ApiOperation("通过id列表更新工资数据(全部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListAllById(@RequestBody Salary salary) {
        return Result.success(salaryService.updateDtoListAllById(salary));
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateById")
    @PreAuthorize("@ss.hasPermi('/salary/updateById')")
    @ApiOperation("通过id更新工资数据(局部更新)")
    public Result<Integer> updateById(@RequestBody Salary salary) {
        return Result.success(salaryService.updateById(salary));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateByIdList")
    @PreAuthorize("@ss.hasPermi('/salary/updateByIdList')")
    @ApiOperation("通过id列表更新工资数据(局部更新)(更新内容相同)")
    public Result<Integer> updateByIdList(@RequestBody Salary salary) {
        return Result.success(salaryService.updateByIdList(salary));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateDtoListById")
    @PreAuthorize("@ss.hasPermi('/salary/updateDtoListById')")
    @ApiOperation("通过id列表更新工资数据(局部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListById(@RequestBody Salary salary) {
        return Result.success(salaryService.updateDtoListById(salary));
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @PreAuthorize("@ss.hasPermi('/salary/findById/{id}')")
    @ApiOperation("通过id查询工资数据")
    @ApiImplicitParam(name = "id", value = "id")
    public Result<Salary> findById(@PathVariable Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(salaryService.findById(id));
    }

    /**
     * 通过id数组查询
     * 
     * @param ids
     * @return
     */
    @GetMapping("/findByIds/{ids}")
    @PreAuthorize("@ss.hasPermi('/salary/findByIds/{ids}')")
    @ApiOperation("通过id数组查询工资数据")
    @ApiImplicitParam(name = "ids", value = "id数组")
    public Result<List<Salary>> findByIds(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(salaryService.findByIds(ids));
    }

    /**
     * 通过对象查询id列表
     * 
     * @param salary
     * @return
     */
    @GetMapping("/findIdByDto")
    @PreAuthorize("@ss.hasPermi('/salary/findIdByDto')")
    @ApiOperation("通过对象查询工资id列表")
    public Result<List<Integer>> findIdByDto(Salary salary) {
        return Result.success(salaryService.findIdByDto(salary));
    }

    /**
     * 通过userId删除(物理删除)
     * 
     * @param userId
     * @return
     */
    @DeleteMapping("/deleteByUserId/{userId}")
    @PreAuthorize("@ss.hasPermi('/salary/deleteByUserId/{userId}')")
    @ApiOperation("通过userId删除工资数据(物理删除)")
    @ApiImplicitParam(name = "userId", value = "userId")
    public Result<Integer> deleteByUserId(@PathVariable Integer userId) {
        if (userId == null) {
            return Result.success();
        }

        return Result.success(salaryService.deleteByUserId(userId));
    }

    /**
     * 通过userId数组删除(物理删除)
     * 
     * @param userIds
     * @return
     */
    @DeleteMapping("/deleteByUserIds/{userIds}")
    @PreAuthorize("@ss.hasPermi('/salary/deleteByUserIds/{userIds}')")
    @ApiOperation("通过userId数组删除工资数据(物理删除)")
    @ApiImplicitParam(name = "userIds", value = "userId数组")
    public Result<Integer> deleteByUserIds(@PathVariable Integer[] userIds) {
        if (userIds.length == 0) {
            return Result.success();
        }

        return Result.success(salaryService.deleteByUserIds(userIds));
    }

    /**
     * 通过userId更新(全部更新)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateAllByUserId")
    @PreAuthorize("@ss.hasPermi('/salary/updateAllByUserId')")
    @ApiOperation("通过userId更新工资数据(全部更新)")
    public Result<Integer> updateAllByUserId(@RequestBody Salary salary) {
        return Result.success(salaryService.updateAllByUserId(salary));
    }

    /**
     * 通过userId列表更新(全部更新)(更新内容相同)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateAllByUserIdList")
    @PreAuthorize("@ss.hasPermi('/salary/updateAllByUserIdList')")
    @ApiOperation("通过userId列表更新工资数据(全部更新)(更新内容相同)")
    public Result<Integer> updateAllByUserIdList(@RequestBody Salary salary) {
        return Result.success(salaryService.updateAllByUserIdList(salary));
    }

    /**
     * 通过userId列表更新(全部更新)(更新内容不相同)
     * 
     * @param salarys
     * @return
     */
    @PutMapping("/updateDtoListAllByUserId")
    @PreAuthorize("@ss.hasPermi('/salary/updateDtoListAllByUserId')")
    @ApiOperation("通过userId列表更新工资数据(全部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListAllByUserId(@RequestBody Salary salarys) {
        return Result.success(salaryService.updateDtoListAllByUserId(salarys));
    }

    /**
     * 通过userId更新(局部更新)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateByUserId")
    @PreAuthorize("@ss.hasPermi('/salary/updateByUserId')")
    @ApiOperation("通过userId更新工资数据(局部更新)")
    public Result<Integer> updateByUserId(@RequestBody Salary salary) {
        return Result.success(salaryService.updateByUserId(salary));
    }

    /**
     * 通过userId列表更新(局部更新)(更新内容相同)
     * 
     * @param salary
     * @return
     */
    @PutMapping("/updateByUserIdList")
    @PreAuthorize("@ss.hasPermi('/salary/updateByUserIdList')")
    @ApiOperation("通过userId列表更新工资数据(局部更新)(更新内容相同)")
    public Result<Integer> updateByUserIdList(@RequestBody Salary salary) {
        return Result.success(salaryService.updateByUserIdList(salary));
    }

    /**
     * 通过userId列表更新(局部更新)(更新内容不相同)
     * 
     * @param salarys
     * @return
     */
    @PutMapping("/updateDtoListByUserId")
    @PreAuthorize("@ss.hasPermi('/salary/updateDtoListByUserId')")
    @ApiOperation("通过userId列表更新工资数据(局部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListByUserId(@RequestBody Salary salarys) {
        return Result.success(salaryService.updateDtoListByUserId(salarys));
    }

    /**
     * 通过userId查询
     * 
     * @param userId
     * @return
     */
    @GetMapping("/findByUserId/{userId}")
    @PreAuthorize("@ss.hasPermi('/salary/findByUserId/{userId}')")
    @ApiOperation("通过userId查询工资数据")
    @ApiImplicitParam(name = "userId", value = "userId")
    public Result<Salary> findByUserId(@PathVariable Integer userId) {
        if (userId == null) {
            return Result.success();
        }

        return Result.success(salaryService.findByUserId(userId));
    }

    /**
     * 通过userId数组查询
     * 
     * @param userIds
     * @return
     */
    @GetMapping("/findByUserIds/{userIds}")
    @PreAuthorize("@ss.hasPermi('/salary/findByUserIds/{userIds}')")
    @ApiOperation("通过userId数组查询工资数据")
    @ApiImplicitParam(name = "userIds", value = "userId数组")
    public Result<List<Salary>> findByUserIds(@PathVariable Integer[] userIds) {
        if (userIds.length == 0) {
            return Result.success();
        }

        return Result.success(salaryService.findByUserIds(userIds));
    }

    /**
     * 通过对象查询userId列表
     * 
     * @param salary
     * @return
     */
    @GetMapping("/findUserIdByDto")
    @PreAuthorize("@ss.hasPermi('/salary/findUserIdByDto')")
    @ApiOperation("通过对象查询工资userId列表")
    public Result<List<Integer>> findUserIdByDto(Salary salary) {
        return Result.success(salaryService.findUserIdByDto(salary));
    }

    /**
     * 通过对象删除(逻辑删除)
     * 
     * @param salary
     * @return
     */
    @DeleteMapping("/logicDeleteByDto")
    @PreAuthorize("@ss.hasPermi('/salary/logicDeleteByDto')")
    @ApiOperation("通过对象删除工资数据(逻辑删除)")
    public Result<Integer> logicDeleteByDto(@RequestBody Salary salary) {
        return Result.success(salaryService.logicDeleteByDto(salary));
    }

    /**
     * 统计所有未删除的数据
     * 
     * @return
     */
    @GetMapping("/countAllByStatusNo")
    @PreAuthorize("@ss.hasPermi('/salary/countAllByStatusNo')")
    @ApiOperation("统计工资所有未删除的数据")
    public Result<Integer> countAllByStatusNo() {
        return Result.success(salaryService.countAllByStatusNo());
    }

    /**
     * 查询所有未删除的数据
     * 
     * @return
     */
    @GetMapping("/findAllByStatusNo")
    @PreAuthorize("@ss.hasPermi('/salary/findAllByStatusNo')")
    @ApiOperation("查询工资所有未删除的数据")
    public Result<List<Salary>> findAllByStatusNo() {
        return Result.success(salaryService.findAllByStatusNo());
    }

    /**
     * 通过id删除(逻辑删除)
     * 
     * @param id
     * @return
     */
    @DeleteMapping("/logicDeleteById/{id}")
    @PreAuthorize("@ss.hasPermi('/salary/logicDeleteById/{id}')")
    @ApiOperation("通过id删除工资数据(逻辑删除)")
    @ApiImplicitParam(name = "id", value = "id")
    public Result<Integer> logicDeleteById(@PathVariable Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(salaryService.logicDeleteById(id));
    }

    /**
     * 通过id数组删除(逻辑删除)
     * 
     * @param ids
     * @return
     */
    @DeleteMapping("/logicDeleteByIds/{ids}")
    @PreAuthorize("@ss.hasPermi('/salary/logicDeleteByIds/{ids}')")
    @ApiOperation("通过id数组删除工资数据(逻辑删除)")
    @ApiImplicitParam(name = "ids", value = "id数组")
    public Result<Integer> logicDeleteByIds(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(salaryService.logicDeleteByIds(ids));
    }

    /**
     * 通过userId删除(逻辑删除)
     * 
     * @param userId
     * @return
     */
    @DeleteMapping("/logicDeleteByUserId/{userId}")
    @PreAuthorize("@ss.hasPermi('/salary/logicDeleteByUserId/{userId}')")
    @ApiOperation("通过userId删除工资数据(逻辑删除)")
    @ApiImplicitParam(name = "userId", value = "userId")
    public Result<Integer> logicDeleteByUserId(@PathVariable Integer userId) {
        if (userId == null) {
            return Result.success();
        }

        return Result.success(salaryService.logicDeleteByUserId(userId));
    }

    /**
     * 通过userId数组删除(逻辑删除)
     * 
     * @param userIds
     * @return
     */
    @DeleteMapping("/logicDeleteByUserIds/{userIds}")
    @PreAuthorize("@ss.hasPermi('/salary/logicDeleteByUserIds/{userIds}')")
    @ApiOperation("通过userId数组删除工资数据(逻辑删除)")
    @ApiImplicitParam(name = "userIds", value = "userId数组")
    public Result<Integer> logicDeleteByUserIds(@PathVariable Integer[] userIds) {
        if (userIds.length == 0) {
            return Result.success();
        }

        return Result.success(salaryService.logicDeleteByUserIds(userIds));
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     */
    @DeleteMapping("/clear")
    @PreAuthorize("@ss.hasPermi('/salary/clear')")
    @ApiOperation("清空工资数据(物理清空)")
    public Result<Integer> clear() {
        return Result.success(salaryService.clear());
    }

    /**
     * 清空数据(逻辑清空)
     * 
     * @return
     */
    @DeleteMapping("/logicClear")
    @PreAuthorize("@ss.hasPermi('/salary/logicClear')")
    @ApiOperation("清空工资数据(逻辑清空)")
    public Result<Integer> logicClear() {
        return Result.success(salaryService.logicClear());
    }

    /**
     * 导入工资
     * 
     * @return
     * @throws Exception 
     */
    @PostMapping("/importSalary")
    @PreAuthorize("@ss.hasPermi('/salary/importSalary')")
    @ApiOperation("导入工资")
    public Result<Integer> importSalary(MultipartFile file) throws Exception {
        return Result.success(salaryService.importSalary(file));
    }

    /**
     * 重新导入工资
     * 
     * @param id
     * @return
     */
    @PutMapping("/reImportSalary/{id}")
    @PreAuthorize("@ss.hasPermi('/salary/reImportSalary/{id}')")
    @ApiOperation("重新导入工资")
    public Result<Integer> reImportSalary(@PathVariable Integer id) {
        return Result.success(salaryService.reImportSalary(id));
    }

    /**
     * 确认工资
     * 
     * @param ids
     * @return
     */
    @PutMapping("/affirm/{ids}")
    @PreAuthorize("@ss.hasPermi('/salary/affirm/{ids}')")
    @ApiOperation("确认工资")
    public Result<Integer> affirm(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(salaryService.affirm(ids));
    }

    /**
     * 取消确认工资
     * 
     * @param ids
     * @return
     */
    @PutMapping("/affirmCancle/{ids}")
    @PreAuthorize("@ss.hasPermi('/salary/affirmCancle/{ids}')")
    @ApiOperation("取消确认工资")
    public Result<Integer> affirmCancle(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(salaryService.affirmCancle(ids));
    }

    /**
     * 发放工资
     * 
     * @param id
     * @return
     */
    @PutMapping("/send")
    @PreAuthorize("@ss.hasPermi('/salary/send')")
    @ApiOperation("发放工资")
    public Result<Integer> send() {
        salaryService.send();
        return Result.success();
    }

    /**
     * 根据对象查询
     * 
     * @param salary
     * @return
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('/salary/list')")
    @ApiOperation("根据对象查询工资数据")
    public Result<List<Salary>> list(Salary salary) {
        return Result.success(salaryService.list(salary));
    }

}